package hackerrank.algorithms.warmup;

import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by Tzachi on 16/10/2014.
 */
public class ServiceLane {

    public static int getArrayMin(int[] input, int startIndex, int endIndex){
        int min = input[startIndex];
        for (int i = startIndex; i<=endIndex; i++){
            if (input[i]<min){
                min = input[i];
            }
        }
        return min;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // N & T
        int freewayLength = in.nextInt();
        int numberOfTestCases = in.nextInt();
        // Width array
        int[] width = new int[freewayLength];
        for (int i = 0; i < freewayLength; i++) {
            width[i] = in.nextInt();
        }
        List<TestCase> testCases = new LinkedList<>();
        for (int i = 0; i < numberOfTestCases; i++) {
            int startPoint = in.nextInt();
            int endPoint = in.nextInt();
            testCases.add(new TestCase(startPoint, endPoint));
        }

        //start checking
        for (TestCase testCase : testCases) {
            System.out.println(getArrayMin(width, testCase.getStartPoint(), testCase.getEndPoint()));
        }
    }

    public static class TestCase {
        private final int startPoint;
        private final int endPoint;

        public TestCase(int startPoint, int endPoint) {
            this.startPoint = startPoint;
            this.endPoint = endPoint;
        }

        public int getStartPoint() {
            return startPoint;
        }

        public int getEndPoint() {
            return endPoint;
        }
    }

}
